import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import Detail from './Detail'
import { Route } from 'react-router-dom'


export default class Message extends Component {
  state = {
    messageArr: [
      {id: '001', title: '消息1'},
      {id: '002', title: '消息2'},
      {id: '003', title: '消息3'},
    ]
  }

  render() {
    const {messageArr} = this.state
    return (
      <div>
        <ul>
          {
            messageArr.map((message)=>{
              return (
                <li key={message.id}>
                  {/* 向路由组件传递params参数 */}
                  {/* <Link to={`/home/message/detail/${message.id}/${message.title}`} >{message.title}</Link>  */}
                  {/* 向路由组件传递search参数 */}
                  <Link to={`/home/message/detail/?id=${message.id}&title=${message.title}`} >{message.title}</Link>
                </li>
              )
            })
          }
        </ul>

        <hr />
        {/* 第一种携带参数的方式 生命接收Params参数 */}
        {/* <Route path="/home/message/detail/:id/:title" component={Detail} /> */}
        {/* 第一种携带参数的方式 声明接收Seacrch参数 无需声明接收，正常声明即可*/}
        <Route path="/home/message/detail" component={Detail} />
      </div>
    )
  }
}
